<!DOCTYPE html>
<html lang="zh-cn">
<head>
	{template wxshare}
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
	<title>{if $record['type']==1}充值 - {php echo $this->module['config']['sname']}{else}支付订单 - {php echo $this->module['config']['sname']}{/if}</title>
	<meta name="format-detection" content="telephone=no, address=no">
	<meta name="apple-mobile-web-app-capable" content="yes" /> <!-- apple devices fullscreen -->
	<meta name="apple-touch-fullscreen" content="yes"/>
	<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
	<link href="{$_W['siteroot']}app/resource/css/bootstrap.min.css" rel="stylesheet">
	<link href="{$_W['siteroot']}app/resource/css/font-awesome.min.css" rel="stylesheet">
	<meta content="telephone=no" name="format-detection">
	<link href="{WELIAM_INDIANA_STATIC}css/common.css" rel="stylesheet">
	<link href="{WELIAM_INDIANA_STATIC}css/pay.css" rel="stylesheet">
	<script type="text/javascript" src="{$_W['siteroot']}app/resource/js/lib/jquery-1.11.1.min.js"></script>
	<script type="text/javascript" src="{WELIAM_INDIANA_STATIC}js/ap.js"></script>
</head>
<body>
<style>
	body{background:#EEE;}
	.container-fill{}
	h4{margin:15px 0;}
	h4:first-of-type{margin-top:10px;}
	.panel{padding:.5em; margin-bottom:10px;}
	.nav.nav-tabs{margin-bottom:.8em;}
	.alert .form-group{margin-bottom:0;}
	label.form-group{display:block;}
	label.form-group{font-weight:normal; overflow:hidden; border-top:1px #DDD solid; padding-top:10px;padding-bottom:0;margin-bottom:0 }
	label.form-group .col-xs-2{margin-top:0px;}
	label.form-group input[name="type"]{opacity:0; width:0;}
	#wq_card .form-group{border-top:none;border-bottom:1px solid #ccc;}
	#wq_card .form-group .col-xs-2{margin-top:15px;}
	#wq_card .form-group:last-child{border-bottom:none}
	.list-group-item{border: 1px solid #FFF;}
	.tr-main{background-color: #FFFFFF;border-top: 1px solid rgba(222,222,220,0.8);border-bottom: 1px solid rgba(222,222,220,0.8);padding-left: 15px;margin-top: 20px;}
	.tr-main p{display: block;heightu: 44px;line-height: 44px;border-bottom: 1px solid rgba(222,222,220,0.8);color: #333333;position: relative; font-size: 15px}
	.tr-main p:last-child{border-bottom:none;}
	p{margin: 0 0 0px;}
	.pull-right{margin-right: 8px;}
	.btn-success{background-color: #04BE02;border-color: #04BE02;}
</style>
<div class="m-simpleHeader" id="pro-view-0">
	<a href="javascript:history.go(-1);" data-pro="back" data-back="true" class="m-simpleHeader-back" style="padding: 11px 15px;">
		<i class="ico ico-back">
		</i>
	</a>
	<h1 style="padding: 11px 15px;">
		{if $record['type']==1}充值{else}支付订单{/if}
	</h1>
</div>
<div class="m-pay-order">
	{if $record['type']!=1}
	<div data-pro="list">
		<div id="pro-view-1">
			<div data-pro="entry" class="m-pay-order-list">
				{loop $thisCart $cart}
				<div class="m-pay-order-list-item" id="pro-view-2">
					<span class="m-pay-order-list-item-name">{$cart['title']}</span><span class="m-pay-order-list-item-num"><b class="txt-red">{$cart['num']}</b>人次</span>
				</div>
				{/loop}
				<input type="hidden" id="openid" name="openid" value="{$record['openid']}" />
				<input type="hidden" id="uniacid" name="uniacid" value="{$record['uniacid']}" />
			</div>
			<div class="m-pay-order-total">
				商品合计：<b class="txt-red">{$money}夺宝币</b>
			</div>
		</div>
	</div>
	{/if}
	<input type="hidden" id="money" name="money" value="{$money}" />
	<div data-pro="options" class="m-pay-order-options" id="choose">
		{if $record['type']!=1}
		<div class="w-checkBar w-bar w-checkBar-disabled " id="" onclick="chgclass(this,'credit2')">
			<span id="pro-view-23">余额支付（余额：{$thismember['credit2']}夺宝币）<span class="txt-red w-bar-extText">{$money}夺宝币</span></span>
			<div class="w-bar-ext">
				<b data-pro="switcher" class="w-checkbox">
				</b>
				<input type="checkbox" disabled="disabled">
			</div>
		</div>
		{/if}
		<div class="w-checkBar w-bar w-checkBar-checked" id="" onclick="chgclass(this,'weixin')">
			<span id="pro-view-24">其他方式支付<span class="txt-red w-bar-extText">{$money}.00元</span></span>
			<div class="w-bar-ext">
				<b data-pro="switcher" class="w-checkbox">
				</b>
				<input type="checkbox">
			</div>
		</div>
	</div>
	{if !empty($mine)}
		{loop $mine $mi}
		<p>{$mi['name']} :<span class="pull-right">{$mi['value']}</span></p>
		{/loop}
	{/if}	
</div>
<div class="panel clearfix" style="border-radius: 0px;" id="weixin">
	<div class="tab-content">
		<div class="tab-pane animated active fadeInLeft" id="direct">
			<div class="pay-btn" id="wechat-panel">
				<input type="hidden" name="params" value="{php echo base64_encode(json_encode($params));}" />
				<input type="hidden" name="encrypt_code" value="" />
				<input type="hidden" name="card_id" value="{php echo base64_encode($card_id);}" />
				<input type="hidden" name="coupon_id" value="" />
				<button class="btn btn-success btn-block col-sm-12" disabled="disabled" type="submit" id="pay" value="wechat" style="height: 42px; font-size: 18px;">支付</button>
			</div>
		</div>
	</div>
</div>
<div class="panel clearfix" style="border-radius: 0px;display: none;" id="credit2" >
	<div class="tab-content">
		<div class="tab-pane animated active fadeInLeft" id="direct">
			<div class="pay-btn" id="wechat-panel">
					<button class="btn btn-success btn-block col-sm-12" disabled="disabled" type="submit" id="wBtn2" value="wechat" style="height: 42px; font-size: 18px;">支付</button>
			</div>
			<script type="text/javascript">
				document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
					$('#wBtn2').removeAttr('disabled');
					$('#wBtn2').html('余额支付');
				});
				$('#wBtn2').bind('click',function(){
					var openid = $('#openid').val();
					var uniacid = $('#uniacid').val();
					$.post("{php echo $this->createMobileUrl('pay',array('type'=>'credit2'))}",{openid:openid,uniacid:uniacid},function(d){
						if(d.result==1){
							tip("余额支付成功!",true);
							var url ="{php echo $this->createMobileUrl('endbuy');}&money="+money;
							location.href=url;
						}else{
							tip(d.why,true);
						}
					},"json");
					
				});
			</script>
		</div>
	</div>
</div>
{template 'common_message'}
<input type="hidden" name="token" value="{$_W['token']}" />
<script type="text/javascript" src="{WELIAM_INDIANA_STATIC}js/pingpp_one.js"></script>
<script>
	var cztype = {$record['type']};
	if(cztype == 1){
		var URL = "http://"+window.location.host+"/app/index.php?i="+{$_W['uniacid']}+"&c=entry&do=person&m=weliam_indiana";
	}else{
		var URL = "http://"+window.location.host+"/app/index.php?i="+{$_W['uniacid']}+"&c=entry&do=endbuy&m=weliam_indiana";
	}
	
	function chgclass(o,type) {
		var u = document.getElementById('choose');
		var c = u.childNodes;
		for (var i = 0; i < c.length; i++) {
			if (c[i].tagName && c[i].tagName.toLowerCase() == 'div') {
				if (c[i] == o) {
					c[i].className = 'w-checkBar w-bar w-checkBar-checked';
					if(type=='weixin'){
						$('#coupon').show();
						$('#weixin').show();
						$('#credit2').hide();
					}
					if(type=='credit2'){
						$('#coupon').hide();
						$('#weixin').hide();
						$('#credit2').show();
					}
				} else {
					c[i].className = 'w-checkBar w-bar w-checkBar-disabled';
				}
			}
		}
	}
	//支付方式判断
	var paytype = [];
	if('{php echo $this->module['config']['isalipay']}' == 2){
		paytype.push('alipay_wap');
	}
	if('{php echo $this->module['config']['iswxpay']}' == 2){
		paytype.push('wx_pub');
	}
	if('{php echo $this->module['config']['isjdpay']}' == 2){
		paytype.push('jdpay_wap');
	}
	if('{php echo $this->module['config']['isbfbpay']}' == 2){
		paytype.push('bfb_wap');
	}
	document.addEventListener('pingpp_one_ready',function(){
		$('#pay').removeAttr('disabled');
		$('#pay').html('其他方式支付');		
        document.getElementById('pay').addEventListener('click',function(){
            pingpp_one.init({
                app_id:'{php echo $this->module['config']['App_ID']}',                     //该应用在 ping++ 的应用 ID
                order_no:'{$params['tid']}',                     //订单在商户系统中的订单号
                amount:{$money},                               //订单价格，单位：人民币 分
                // 壹收款页面上需要展示的渠道，数组，数组顺序即页面展示出的渠道的顺序
                // upmp_wap 渠道在微信内部无法使用，若用户未安装银联手机支付控件，则无法调起支付
                channel:paytype,
                charge_url:"{php echo $this->createMobileUrl('pay_ping')}",  //商户服务端创建订单的 url
                charge_param:{cztype:cztype},                      //(可选，用户自定义参数，若存在自定义参数则壹收款会通过 POST 方法透传给 charge_url)
                open_id:'{$openid}',                      //(可选，使用微信公众号支付时必须传入)
                debug:false                                   //(可选，debug 模式下会将 charge_url 的返回结果透传回来)
            },function(res){
                //debug 模式下获取 charge_url 的返回结果
                if(res.debug&&res.chargeUrlOutput){
                    console.log(res.chargeUrlOutput);
                }
                if(!res.status){
                    //处理错误
                    alert(res.msg);
                }
                else{
                    //debug 模式下调用 charge_url 后会暂停，可以调用 pingpp_one.resume 方法继续执行
                    if(res.debug&&!res.wxSuccess){
                        if(confirm('当前为 debug 模式，是否继续支付？')){
                            pingpp_one.resume();
                        }
                    }
     
                    window.location.href = URL;
                }
            });
        });
    });
</script>
{template 'common/footer'}